from sys import maxint

class Thing: 
  def isNumeric(o) : return False
  def put(o,x) : 
    return x if x == '?' else o.put1(x)

class Num(Thing):
    def isNumeric(o) : return True
    def __init__(o,i,name,prep=lambda x:float(x),isKlass=False) : 
      o.breaks=[]
      o.name=name
      o.weight=1; o.isKlass = isKlass; o.prep= prep; 
      o.i = i; o.max= -1*maxint - 1 ; o.min = maxint;
      o.n=o.sum=o.s2=0
    def put1(o,x)     : 
      x = o.prep(x); o.max= max(o.max,x); 
      o.min= min(o.min,x); 
      o.n += 1; o.sum += x; o.s2 += x*x; return x
    def getBreaks(o,nums,bin) :
      o.breaks = breaks(nums,bins)
      return o.breaks
    def __repr__(o) : return 'Num('+o.name+'[%s..%s]' % (o.min,o.max)+')'
 
class Sym(Thing): 
    def __init__(o,i,name,isKlass=False) : 
      o.weight=1 ; o.isKlass=isKlass; o.i = i; 
      o.name=name; o.counts={}; o.most = -1
    def put1(o,x)     : 
      new = o.counts[x] = o.counts.get(x,0) + 1
      if new > o.most : o.most,o.mode=new,x
      return x
    def __repr__(o) : return 'Sym('+o.name+')'
